package com.ruoyi.voucher.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.voucher.mapper.VoucherAttachmentMapper;
import com.ruoyi.voucher.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.VoucherAttachment;
import com.ruoyi.voucher.service.IVoucherAttachmentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 凭证附件Controller
 * 
 * @author ruoyi
 * @date 2025-02-26
 */

@RestController
@RequestMapping("/attachment")
public class VoucherAttachmentController extends BaseController
{

    @Autowired
    private IVoucherAttachmentService voucherAttachmentService;
    @Autowired
    private VoucherAttachmentMapper voucherAttachmentMapper;

    /**
     * 查询凭证附件列表
     */

    @GetMapping("/list")
    public TableDataInfo list(VoucherAttachment voucherAttachment)
    {
        startPage();
        List<VoucherAttachment> list = voucherAttachmentService.selectVoucherAttachmentList(voucherAttachment);
        return getDataTable(list);
    }


    /**
     * 导出凭证附件列表
     */
    @RequiresPermissions("voucher:attachment:export")
    @Log(title = "凭证附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherAttachment voucherAttachment)
    {
        List<VoucherAttachment> list = voucherAttachmentService.selectVoucherAttachmentList(voucherAttachment);
        ExcelUtil<VoucherAttachment> util = new ExcelUtil<VoucherAttachment>(VoucherAttachment.class);
        util.exportExcel(response, list, "凭证附件数据");
    }




    /**
     * 获取凭证附件详细信息
     */
    @RequiresPermissions("voucher:attachment:query")
    @GetMapping(value = "/{attachmentId}")
    public AjaxResult getInfo(@PathVariable("attachmentId") Long attachmentId)
    {
        return success(voucherAttachmentService.selectVoucherAttachmentByAttachmentId(attachmentId));
    }


    /**
     * 新增凭证附件
     */
    @RequiresPermissions("voucher:attachment:add")
    @Log(title = "凭证附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoucherAttachment voucherAttachment)
    {
        return toAjax(voucherAttachmentService.insertVoucherAttachment(voucherAttachment));
    }

    /**
     * 修改凭证附件
     */
    @RequiresPermissions("voucher:attachment:edit")
    @Log(title = "凭证附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoucherAttachment voucherAttachment)
    {
        return toAjax(voucherAttachmentService.updateVoucherAttachment(voucherAttachment));
    }

    /**
     * 删除凭证附件
     */
    @RequiresPermissions("voucher:attachment:remove")
    @Log(title = "凭证附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attachmentIds}")
    public AjaxResult remove(@PathVariable Long[] attachmentIds)
    {
        return toAjax(voucherAttachmentService.deleteVoucherAttachmentByAttachmentIds(attachmentIds));
    }
}
